package com.example.himalaya.model;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

import com.example.himalaya.constants.Constants;

public class XimalayaDBHelper extends SQLiteOpenHelper {

    public XimalayaDBHelper(@Nullable Context context) {

        // name 数据库的名字
        // factory 游标工厂
        // version 版本
        super(context, Constants.DB_NAME, null, Constants.DB_VERSION_CODE);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // 创建数据表
        // 订阅相关的字段
        String subTbSql = "create table " + Constants.SUB_TB_NAME + "(" +
                Constants.SUB_ID + " integer primary key autoincrement," +
                Constants.SUB_COVER_URL + " varchar," +
                Constants.SUB_TITLE + " varchar," +
                Constants.SUB_DESCRIPTION + " varchar," +
                Constants.SUB_PLAY_COUNT + " integer," +
                Constants.SUB_TRACK_COUNT + " integer," +
                Constants.SUB_AUTHOR_NAME + " varchar," +
                Constants.SUB_ALBUM_ID + " integer" +
                ")";

        // 创建订阅表
        db.execSQL(subTbSql);

        // 创建历史表

        String historyTbSql = "create table " + Constants.HISTORY_TB_NAME + "(" +
                Constants.HISTORY_ID + " integer primary key autoincrement," +
                Constants.HISTORY_COVER_URL + " varchar," +
                Constants.HISTORY_TITLE + " varchar," +
                Constants.TRACK_AUTHOR_NAME + " varchar," +
                Constants.HISTORY_PLAY_COUNT + " integer," +
                Constants.HISTORY_UPDATE_TIME + " integer," +
                Constants.HISTORY_DURATION + " integer," +
                Constants.HISTORY_TRACK_ID + " integer" +
                ")";

        db.execSQL(historyTbSql);


        // 创建喜爱音乐的表

        String loveSongTbSql = "create table " + Constants.LOVE_SONG_TB_NAME + "(" +
                Constants.LOVE_SONG_ID + " integer primary key autoincrement," +
                Constants.LOVE_SONG_COVER_URL + " varchar," +
                Constants.LOVE_SONG_TITLE + " varchar," +
                Constants.TRACK_AUTHOR_NAME + " varchar," +
                Constants.LOVE_SONG_PLAY_COUNT + " integer," +
                Constants.LOVE_SONG_UPDATE_TIME + " integer," +
                Constants.LOVE_SONG_DURATION + " integer," +
                Constants.LOVE_SONG_TRACK_ID + " integer" +
                ")";

        db.execSQL(loveSongTbSql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}
